import http from '@/utils/httpRequest'
import ApiUrl from '@/constant/api-url'

let config = {
  headers: {
    'Content-Type': 'multipart/form-data;charset=utf-8'
  },
  transformRequest: [function (data) {
    return data
  }]
}

const fileApi = {
  /**
   * 上传文件
   * @param params
   * @returns {AxiosPromise}
   */
  uploadFile: function (params) {
    return http({
      url: http.adornUrl('api/sys/file/upload'),
      method: 'post',
      timeout: 20000,
      data: params,
      config
    })
  },
  /**
   * 下载文件（通用）
   * @param params
   * @returns {AxiosPromise}
   */
  download: function (params) {
    return http({
      url: http.adornUrl('api/sys/file/download'),
      method: 'get',
      timeout: 20000,
      params: http.adornParams(params),
      responseType: 'blob'
    })
  },
  /**
   * 下载模板
   * @returns {AxiosPromise}
   */
  downloadTemplate: function (params) {
    return http({
      url: http.adornUrl('api/sys/file/download-template'),
      method: 'get',
      timeout: 20000,
      params: http.adornParams(params),
      responseType: 'blob'
    })
  },
  /**
   * 导入数据
   * @returns {AxiosPromise}
   */
  uploadData: function (params) {
    return http({
      url: http.adornUrl('api/sys/file/import'),
      method: 'post',
      timeout: 20000,
      data: params,
      config
    })
  },
  /**
   * 上传文件(通用)
   * @param params
   * @returns {AxiosPromise}
   */
  uploadFiles: function (params) {
    return http({
      baseURL: ApiUrl.API_HOST_BASE,
      url: http.adornUrl('api/sys/file/upload-file'),
      method: 'post',
      timeout: 20000,
      data: params,
      config
    })
  },
  /**
   * 下载图片（通用）
   * @param params
   * @returns {AxiosPromise}
   */
  downloadImage: function (params) {
    return http({
      baseURL: ApiUrl.API_HOST_BASE,
      url: http.adornUrl('api/sys/file/download-image'),
      method: 'get',
      timeout: 20000,
      params: http.adornParams(params)
    })
  }
}
export default fileApi
